package com.sundae.smarthomedemo.Activitys;

import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.animation.AccelerateInterpolator;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;

import com.jaeger.library.StatusBarUtil;
import com.sundae.smarthomedemo.MyAppConfig;
import com.sundae.smarthomedemo.R;
import com.sundae.smarthomedemo.Utils.ToastUtils;

import immortalz.me.library.TransitionsHeleper;
import immortalz.me.library.bean.InfoBean;
import immortalz.me.library.method.ColorShowMethod;

public class PersonalActivity extends BaseActivity {

    private ImageButton back_button;

    private ImageView title_image;
    private TextView logininfo_textView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_personal);

        TransitionsHeleper.getInstance()
                .setShowMethod(new ColorShowMethod(R.color.grayColor,R.color.styleColor) {
                    @Override
                    public void loadCopyView(InfoBean bean, ImageView copyView) {
                        AnimatorSet set = new AnimatorSet();
                        set.playTogether(
                                ObjectAnimator.ofFloat(copyView,"rotation",0,180),
                                ObjectAnimator.ofFloat(copyView, "scaleX", 1, 0),
                                ObjectAnimator.ofFloat(copyView, "scaleY", 1, 0)
                        );
                        set.setInterpolator(new AccelerateInterpolator());
                        set.setDuration(duration / 4 * 5).start();
                    }

                    @Override
                    public void loadTargetView(InfoBean bean, ImageView targetView) {
                    }
                })
                .show(this,null);

        StatusBarUtil.setColor(this , getResources().getColor(R.color.styleColor) , 0);

        initView();
    }

    @Override
    protected void onStart() {
        super.onStart();
        SharedPreferences sharedPreferences = getSharedPreferences(MyAppConfig.ShareP_Name , 0);
        if(sharedPreferences.getString("username" , "").equals(""))
        {
            MyAppConfig.user_name = "";
            logininfo_textView.setText("您好，请登陆");
        }else{
            logininfo_textView.setText("点击登出");
        }
    }

    private void initView()
    {
        back_button = (ImageButton) findViewById(R.id.per_backButton);
        back_button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        title_image = (ImageView) findViewById(R.id.personal_title_image);
        logininfo_textView = (TextView) findViewById(R.id.personal_text);
        logininfo_textView.setClickable(true);
        title_image.setClickable(true);

        title_image.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(PersonalActivity.this , LoginActivity.class));
            }
        });
        logininfo_textView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(PersonalActivity.this , LoginActivity.class));
            }
        });

        findViewById(R.id.personal_add_device).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(PersonalActivity.this , SelectWiFiActivity.class));
            }
        });

        findViewById(R.id.aboutme).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ToastUtils.showLongToast(PersonalActivity.this , "希望能够得到实习机会\n （＾ω＾）");
                Intent intent = new Intent(PersonalActivity.this , ShopActivity.class);
                intent.putExtra("url" , "file:///android_asset/jianli.html");
                startActivity(intent);
            }
        });

        findViewById(R.id.my_blog).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ToastUtils.showLongToast(PersonalActivity.this , "希望能够得到实习机会\n （＾ω＾）");
                Intent intent = new Intent(PersonalActivity.this , ShopActivity.class);
                intent.putExtra("url" , "http://www.jianshu.com/u/42fd054c7b41");
                startActivity(intent);
            }
        });
    }
}
